// dp[i][j]表示0~i个数变成b中0~j个数的最小操作步骤
// dp[i][j] = max()
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

const int N = 1010, INF = 0x3f;
char a[N], b[N];
int dp[N][N];
int n, m;
// 求最小值，那就要记得先把数组预处理成无穷大
int main()
{
    cin >> n >> (a + 1) >> m >> (b + 1);
    // 预处理dp数组
    memset(dp, INF, sizeof dp);
    int len = max(n, m);
    for (int i = 0; i <= len; ++i)
    {
        dp[i][0] = i;
        dp[0][i] = i;
    }
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
        {
            dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1;
            dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + (a[i] != b[j]));
        }
    cout << dp[n][m] << endl;
    return 0;
}